﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

/// <summary>
/// Summary description for YKienKHDAL
/// </summary>
public class YKienKHDAL
{
	public YKienKHDAL()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public int fnG_InsertYKienKH(YKienKhachHangEntity YKien)
    {
        string sql = "INSERT INTO YKienKhachHang VALUES(@Tieude,@TenKH,@DienThoai,@DiaChi,@NgayGui,@NoiDung,@Email)";
        return DataProvider.ExecuteNonQuery(sql, "@Tieude", YKien.TieuDe, "@TenKH", YKien.TenKH, "@DienThoai", YKien.DienThoai, "@DiaChi", YKien.DiaChi, "@NgayGui", YKien.NgayGui, "@NoiDung", YKien.NoiDung, "@Email", YKien.Email);
    }
    public DataTable fnG_GetDataAllYkien()
    {
        string strSQL = "select * from YKienKhachHang";
        return DataProvider.GetData(strSQL);

    }

    public void Delete(string ykid)
    {
        string sql = " DELETE YKienKhachHang WHERE idyk=@idyk";
        DataProvider.ExecuteNonQuery(sql, "@idyk",ykid);
    }

    public YKienKhachHangEntity GetYKien(string idyk)
    {
        string sql = " SELECT * FROM YKienKhachHang WHERE idyk=@idyk";
        DataTable table = DataProvider.GetData(sql, "@idyk", idyk);
        YKienKhachHangEntity ykien = new YKienKhachHangEntity();
        ykien.DiaChi = table.Rows[0]["DiaChi"].ToString();
        ykien.DienThoai = table.Rows[0]["DienThoai"].ToString();
        ykien.Email = table.Rows[0]["Email"].ToString();
        ykien.IdYK = Int32.Parse(table.Rows[0]["IdYK"].ToString());
        ykien.NgayGui = DateTime.Parse(table.Rows[0]["NgayGui"].ToString());
        ykien.NoiDung = table.Rows[0]["NoiDung"].ToString();
        ykien.TenKH = table.Rows[0]["TenKH"].ToString();
        ykien.TieuDe = table.Rows[0]["TieuDe"].ToString();
        return ykien;
    }

    public void AddNew(YKienKhachHangEntity ykien)
    {
        string sql = " INSERT INTO YKienKhachHang([TieuDe],[TenKH],[DienThoai],[DiaChi],[NgayGui],[NoiDung],[Email]) VALUES " +
            "(@TieuDe,@TenKH,@DienThoai,@DiaChi,@NgayGui,@NoiDung,@Email)";
        DataProvider.ExecuteNonQuery(sql, "@TieuDe",ykien.TieuDe,"@TenKH",ykien.TenKH,"@DienThoai",ykien.DienThoai,"@DiaChi",ykien.DiaChi,"@NgayGui",ykien.NgayGui,"@NoiDung",ykien.NoiDung,"@Email",ykien.Email);
    }
}